package com.gitee.tianchaohongyu.jdcl.support;

import com.gitee.tianchaohongyu.jdcl.core.Cleaner;
import com.gitee.tianchaohongyu.jdcl.core.CleanerAnnotation;

import javax.validation.constraints.NotNull;
import java.lang.annotation.*;

/**
 * 去首尾空
 */
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(value = {ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE, ElementType.METHOD})
@CleanerAnnotation(Trim.TempCleaner.class)
public @interface Trim {

  /**
   * 清洗器实现
   */
  class TempCleaner implements Cleaner<String, Trim> {

    @Override
    public <R extends String> R clean(R data, @NotNull Class<R> defineType, Trim annotation) {
      @SuppressWarnings("unchecked")
      R ret = data == null ? null : (R) data.trim();
      return ret;
    }
  }
}
